function [ time, OptO ] = Spectral_Perm( C, d, K )

[N, ~] = size(C);
n = N/d;

time_start = tic;
[P,~] = eigs(C,d);

OptO = P;
P0 = P;
OptV = -Inf;
for sample = 1:K
    randO = unirandO(d);
    for i = 1:n
        X = -P( (i-1)*d+1:i*d , : ) * randO;
        [assignment, ~] = assignmentoptimal(X);
        A = zeros(d);
        A((1:d)'+(assignment-1)*d) = 1;
        P0( (i-1)*d+1:i*d , : ) = A;
    end
    optvi = sum(dot(P0, C * P0));
    if optvi > OptV
        OptO = P0;
        OptV = optvi;
    end
end

time = toc(time_start);

end

